﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HRM.Data.Database;

namespace HRM.Data.Repository
{
    public class UserRepository: BaseRepository<User>
    {
        public override IEnumerable<User> GetList()
        {
            return _database.Users.ToList();
        }

        public override User GetById(long id)
        {
            return _database.Users.Find(id);
        }

        public override void Create(User entity)
        {
            _database.Users.Add(entity);
            SaveChanges();
        }

        public override void Update(User entity)
        {
            var tempEntiry = _database.Users.Find(entity.Id);
            _database.Entry(tempEntiry).CurrentValues.SetValues(entity);
            SaveChanges();
        }

        public override void Delete(User entity)
        {
            _database.Users.Remove(entity);
            SaveChanges();
        }

        public User GetUserByEmail(string email)
        {
            return _database.Users.FirstOrDefault(x => x.Email.Equals(email));
        }
    }
}
